{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane" lay-filter="form">

          <div class="layui-form-item">
              <label class="layui-form-label">{:lang('teacher_no')}</label>
              <div class="layui-input-4">
                  <input type="text" name="teacher_no" lay-verify="required" placeholder="{:lang('pleaseEnter')}编号" class="layui-input" value="{$info.teacher_no}" readonly>
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">{:lang('username')}</label>
              <div class="layui-input-4">
                  <input type="text" name="user_name" lay-verify="required" placeholder="{:lang('pleaseEnter')}登录用户名" class="layui-input" value="{$info.user_name}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  用户名在4到25个字符之间。
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">{:lang('pwd')}</label>
              <div class="layui-input-4">
                  <input type="password" name="password" placeholder="{:lang('pleaseEnter')}登录密码" class="layui-input" value="{$info.password}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  密码必须大于6位，小于15位。
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">{:lang('true_name')}</label>
              <div class="layui-input-4">
                  <input type="text" name="true_name"  lay-verify="required" placeholder="{:lang('pleaseEnter')}{:lang('true_name')}" class="layui-input" value="{$info.true_name}">
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">{:lang('sex')}</label>
              <div class="layui-input-4">
                  <div class="layui-input-block">
                      <input type="radio" name="sex" value="1" title="保密" {$info.sex==0?'checked':''}>
                      <input type="radio" name="sex" value="1" title="男" {$info.sex==1?'checked':''}>
                      <input type="radio" name="sex" value="2" title="女" {$info.sex==2?'checked':''}>
                  </div>
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">{:lang('tel')}</label>
              <div class="layui-input-4">
                  <input type="text" name="mobile" lay-verify="phone"  placeholder="{:lang('pleaseEnter')}{:lang('tel')}" class="layui-input" value="{$info.mobile}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  用于密码找回，请认真填写。
              </div>
          </div>

          <div class="layui-form-item">
              <label class="layui-form-label">{:lang('section')}</label>
              <div class="layui-input-inline">
                  <select name="section_id" lay-filter="section_id" lay-verify="required">
                      <option value="" disabled="">请选择教师部门</option>
                      {volist name="sectionGroup" id="vo"}
                      <option value="{$vo.section_id}" {$vo.section_id==$info.section_id?'selected':''}>{$vo.title}</option>
                      {/volist}
                  </select>
              </div>
          </div>
          <div class="position">
              <div class="layui-form-item">
                 <label class="layui-form-label">{:lang('position')}</label>
                 <div class="layui-input-inline">
                     <select lay-filter="position_id">
                         <option value="">请选择任职</option>
                         {volist name="positionGroup" id="vo"}
                         <option value="{$vo.position_id}" name="{$vo.position_name}">{$vo.position_name}</option>
                         {/volist}
                     </select>
                </div>
             </div>
         </div>
        {volist name="info['position_id']" id="vo"}
        <div class="layui-form-item" id="p_item{$vo.id}">
            <label class="layui-form-label">已选任职</label>
            <div class="layui-input-inline">
                <input type="text"  name="position_id" lay-verify="required" class="layui-input" value="{$vo.name}">
            </div>
            <input type="radio" name="position_id" position_id="{$vo.id}" id="position_radio{$vo.id}" title="主职务" {$vo.status=='1'?checked:''}>
            <button class="layui-btn layui-btn-primary layui-btn-sm romove"  position_id="{$vo.id}">移除</button>
        </div>
        {/volist}


        <div class="layui-form-item">
             <label class="layui-form-label">{:lang('degree')}</label>
             <div class="layui-input-4">
                 <input type="text" name="degree"  lay-verify="required"  placeholder="{:lang('pleaseEnter')}{:lang('degree')}" class="layui-input" value="{$info.degree}">
             </div>
        </div>
        <div class="layui-form-item">
             <label class="layui-form-label">{:lang('graduation_school')}</label>
             <div class="layui-input-4">
                 <input type="text" name="graduation_school" lay-verify="required"  placeholder="{:lang('pleaseEnter')}{:lang('graduation_school')}" class="layui-input"  value="{$info.graduation_school}">
             </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$info.id}">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('lists')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script>
    layui.use(['form', 'layer','upload'], function () {
        var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload;
/*        var info = {$info|raw};
        console.log(info);
        form.val("form", info);*/
        /*if(info){
            $('#adPic').attr('src',info.avatar);
        }*/
        form.render();

        //职务操作
        form.on('select(position_id)', function(data){

            position_id = data.value;
            if((position_id!=0)&&($("#p_item"+position_id).attr("class")==undefined)){

                position_name = data.elem[data.elem.selectedIndex].text;

                var item = "<div class=\"layui-form-item\" id='p_item"+position_id+"'>\n" +
                    "            <label class=\"layui-form-label\">{:lang('position')}</label>\n" +
                    "            <div class=\"layui-input-inline\">\n" +
                    "                <input type=\"text\" value='"+position_name+"' class=\"layui-input\" readOnly=\"true\" >\n" +
                    "            </div>\n" +
                    "            <input type=\"radio\" name=\"position_id\" value='1' position_id='"+position_id+"' title=\"主职务\" id='position_radio"+position_id+"'>\n"+
                    "            <button class=\"layui-btn layui-btn-primary romove layui-btn-sm\" position_id='"+position_id+"'>移除</button>\n"+
                    "        </div>";

                $(".position").after(item);
                form.render();
            }
        });

        //移除元素
        $(document).on('click','.romove',function(){

            $("#p_item"+$(this).attr('position_id')).remove();

        });


        form.on('submit(submit)', function (data) {

            var duty= $('input[id^="position_radio"]');

            var numArr = {}; // 定义一个空对象

            for (var i = 0; i < duty.length; i++) {
                var position_id = duty.eq(i).attr('position_id');

                if(duty.eq(i)[0].checked){
                    numArr[position_id] = 1;
                }else{
                    numArr[position_id] = 0;
                }

            }
            data.field.position_id = numArr;
            loading =layer.load(1, {shade: [0.1,'#fff']});

            $.post("{:url('teacherEdit')}", data.field, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
        });

    });

</script>